package authuserbc

// 前端 https(明文)  + 后端 bcrypt 加密存储
import (
	"gitee.com/tgodfather/utility/auth"
	"golang.org/x/crypto/bcrypt"
)

// login  	uesrname   	-  用户名
//			password    -  真实密码， 因此传输层必须采用https

type UserValidator struct {
	username string //输入的username字段内容
	password string //输入的password字段内容

	// cost int    // bcrypt 的参数
}

func (v *UserValidator) VUsername() string {
	return v.username
}

// Password() string
func (v *UserValidator) VPassword() string {
	return v.password
}

func (v *UserValidator) Key() string {
	return v.password //名字有点混乱， 需要考虑调整
}

func (v *UserValidator) GenerateKey(pass string) (string, error) {

	hash, err := bcrypt.GenerateFromPassword([]byte(pass), bcrypt.DefaultCost)

	return string(hash), err
}

func NewUserValidator(username, password string, opt ...auth.ValidatorOption) auth.Validator {

	inUsername := username
	inPassword := password

	return &UserValidator{
		username: inUsername,
		password: inPassword,
	}
}
